package com.atao.baokede.controller;

import com.atao.baokede.pojo.District;
import com.atao.baokede.pojo.Result;
import com.atao.baokede.service.DistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 区域层
 */
@RestController
@RequestMapping("/districts")
public class DistrictController {

    @Autowired
    private DistrictService districtService;

    /**
     * 获取所有省份
     * @return 所有省份列表
     */
    @GetMapping("/provinces")
    public Result<List<String>> getAllProvinces() {
        List<String> provinces = districtService.getAllProvinces();
        return Result.success(provinces);
    }

    /**
     * 获取某个省份下的所有城市
     * @param provinceName
     * @return
     */
    @GetMapping("/cities")
    public Result<List<String>> getCitiesByProvinceName(@RequestParam String provinceName) {
        List<String> cities = districtService.getCitiesByProvinceName(provinceName);
        return Result.success(cities);
    }

    /**
     * 根据省名和市名查询区县
     * @param provinceName 省份名
     * @param cityName 市名
     * @return 区县列表
     */
    @GetMapping("/districts")
    public Result<List<String>> getDistrictsByProvinceAndCityName(
            @RequestParam String provinceName,
            @RequestParam String cityName) {
        List<String> districts = districtService.getDistrictsByProvinceAndCityName(provinceName, cityName);
        return Result.success(districts);
    }
}